/**
 * Copyright (C), 2001-2031, www.bosssof.com.cn
 * FileName: ReceiveServerMessage.java
 * Author: ckj
 * Date: 2024/7/21 下午10:11
 * Description:
 * 用于服务器发给用户的消息
 * History:
 * Date          Author   Version  Desc
 * 2024-01-01    bosssoft  1.0.0   initialize this file
 */
package com.bosssoft.message;

import com.bosssoft.utils.ReaderUtil;

import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.List;

import static com.bosssoft.constants.MessageTypeConstant.THE_SERVER_SENDS_FILES_TO_THE_USER;


/**
 * @author ckj
 */
public class ReceiveServerFile extends BaseMessage{
    private List<String> fileContent ;
    private String fileName;

    /**
     *
     * @author ckj
     * @date 2024/07/22 下午10:41
     * 按照特定的格式从输入流中读取文件名和文件的具体内容行，并将其组织到当前对象中，最后返回当前对象作为解析的结果。
     * @param reader
     * @param type
     * @return com.bosssoft.message.BaseMessage
     */
    @Override
    public BaseMessage parse(BufferedReader reader, Integer type) throws Exception {
        this.setFileName(ReaderUtil.readLineWithAes(reader));
        int contentLength = Integer.parseInt(ReaderUtil.readLineWithAes(reader));
        setFileContent(new ArrayList<>());
        for (int i = 0; i < contentLength; i++) {
            this.fileContent.add(ReaderUtil.readLineWithAes(reader));
        }
        ReaderUtil.readLineWithAes(reader);
        return this;
    }

    /**
     *
     * @author ckj
     * @date 2024/07/22 下午10:41
     * 创建一个具有特定结构和数据的 ReceiveServerFile 对象
     * @return com.bosssoft.message.ReceiveServerFile
     */
    public ReceiveServerFile sendMessageBuild(String fileName,List<String> fileContent) {
        this.setType(THE_SERVER_SENDS_FILES_TO_THE_USER);
        this.setHeader(new ArrayList<>());
        this.getHeader().add(fileName);
        this.setContent(fileContent);
        return this;
    }

    public List<String> getFileContent() {
        return fileContent;
    }

    public void setFileContent(List<String> fileContent) {
        this.fileContent = fileContent;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }
}